﻿using System;
using System.Net;
using System.Collections.Generic;
using System.Linq;

namespace BaseArith {
    public class ChainedTable<T> {
        class Node : INode<T> {
            #region INode 成员
            public T Data { get; set; }
            public int Index { get; set; }
            public string Key { get; set; }
            #endregion
            internal Node previous;
        }
        public ChainedTable() {
            this.pCount = 0;
        }
        Node root,current;
        public int pCount { get; private set; }
        public void Add(T data) {
            var node = new Node { Data = data };
            node.previous = this.current;
            this.current = node;
            this.root = this.current;
            this.pCount++;
        }
        public void RemoveAt(int index) {
            var list = this.QueryNode().ToList();
            if (list[index - 1] != null && list[index + 1] != null) {
                list[index - 1].previous = list[index + 1];
            }
            list[index] = null;
        }
        public void Remove(T t) { 

        }
        IEnumerable<Node> QueryNode() {
            this.current = this.root;
            while (this.current != null) {
                yield return this.current;
                this.current = this.current.previous;
            }
        }
        public IEnumerable<T> Query() {
            this.current = this.root;
            while (this.current != null) {
                yield return this.current.Data;
                this.current = this.current.previous;
            }
        }
    }
}
